#include "KillScore.h"
#include <math.h>


KillScore::KillScore() {
}
KillScore::~KillScore() {
}

void KillScore::Initialize(sf::RenderWindow* window, Gui* gui, sf::Texture* texture) {
	m_renderWindow = window;
	m_gui = gui;
	m_clock = new sf::Clock();

	atScore = false;
	speed = 160;
	scoreSprite = new sf::Sprite;
	scoreSprite->setTexture(*texture);	
	m_alpha = 255;
	m_scale = 1.0f;
}
void KillScore::Update() {
	timeSinceLastFrame = m_clock->restart();
	scoreSprite->move(0, -speed*timeSinceLastFrame.asSeconds());
	
	if (m_alpha > 0) {
		m_alpha -= 250*timeSinceLastFrame.asSeconds();
	}
	if (m_alpha < 0) {
		m_alpha = 0;
	}
	m_scale+= 1*timeSinceLastFrame.asSeconds();

	scoreSprite->setColor(sf::Color(scoreSprite->getColor().r, scoreSprite->getColor().g, scoreSprite->getColor().b, m_alpha));
	scoreSprite->setScale(m_scale,m_scale);

	/*
	scoreAngle = atan2(((m_gui->m_scoreNr->getPosition().y) - scoreSprite->getPosition().y), ((m_gui->m_scoreNr->getPosition().x) - scoreSprite->getPosition().x));
	scoreSprite->move(speed * cos(scoreAngle) * timeSinceLastFrame.asSeconds(), speed * sin(scoreAngle) * timeSinceLastFrame.asSeconds());
	*/

	
	if (scoreSprite->getPosition().y <= m_gui->m_scoreNr->getPosition().y) {
		atScore = true;
	}
	

	

	m_renderWindow->draw(*scoreSprite);
}

void KillScore::Cleanup() {
	delete scoreSprite;
}

void KillScore::setPositionKillScore(float PosX, float PosY) {

	scoreSprite->setPosition(PosX, PosY);
};